package org.adream.account.service;

import org.adream.account.aop.annotation.DataSource;
import org.adream.account.dao.Dream2020DonornDao;
import org.adream.account.entity.Dream2020DonornEntity;
import org.adream.account.model.ResultModel;
import org.adream.account.util.Constant;
import org.adream.account.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 新版盒子捐赠方service
 * @author sl
 *
 */
@Service
@DataSource("adreambox2020DataSource")
public class Dream2020DonornService {
	
	@Autowired
	private Dream2020DonornDao dream2020DonornDao;
	
	private final static Logger logger = LoggerFactory.getLogger(Dream2020DonornService.class);
	
	/**
	 * 新增或更新新版盒子捐赠方
	 * @param dream2020DonornEntity
	 * @return
	 */
	public ResultModel<?> addOrUpdateDream2020Donorn(Dream2020DonornEntity dream2020DonornEntity) {
		//根据id查询捐赠方
		Dream2020DonornEntity dream2020Donorn = dream2020DonornDao.queryDream2020DonornById(dream2020DonornEntity.getId());
		if(dream2020Donorn == null) {
			dream2020DonornEntity.setDeleteTime(null);
			int addDream2020DonornResult = dream2020DonornDao.addDream2020Donorn(dream2020DonornEntity);
			if(addDream2020DonornResult == Constant.ZERO) {
				logger.warn("新增新版盒子捐赠方失败,数据库错误:(");
				return new ResultModel<String>(ResultModel.ERR_DATABASE, "新增新版盒子捐赠方失败,请联系管理员", null);
			}
			return new ResultModel<String>(ResultModel.SUCCESS, "新增新版盒子捐赠方成功", null);
		}
		Utils.copyPropertiesIgnoreNull(dream2020DonornEntity, dream2020Donorn);
		dream2020DonornDao.updateDream2020Donorn(dream2020Donorn);
		return new ResultModel<String>(ResultModel.SUCCESS, "更新捐赠方成功", null);
	}
}